package com.tecsup.log.servlet;

import java.io.IOException;

import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.tecsup.log.modelo.ProductoMaterial;
import com.tecsup.log.dao.ProductoMaterialDAO;
import excepcion.DAOExcepcion;

/**
 * Servlet implementation class ProductoMaterialModificarServlet
 */
@WebServlet("/ProductoMaterialModificarServlet")
public class ProductoMaterialModificarServlet extends HttpServlet {
	private static final long serialVersionUID = 1L;
       
    /**
     * @see HttpServlet#HttpServlet()
     */
    public ProductoMaterialModificarServlet() {
        super();
        // TODO Auto-generated constructor stub
    }

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
	}

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
		
		int x1 = Integer.parseInt(request.getParameter("idp"));
		int x2 = Integer.parseInt(request.getParameter("idm"));
		double x3 = Double.parseDouble(request.getParameter("unidades"));
		


		ProductoMaterial vo = new ProductoMaterial();
		vo.setIdProducto(x1);
		vo.setIdMaterial(x2);
		vo.setUnidades(x3);
		
		ProductoMaterialDAO dao = new ProductoMaterialDAO();
		try {
			dao.actualizar(vo);
			response.sendRedirect(request.getContextPath()
					+ "/ProductoBuscarServlet");
		} catch (DAOExcepcion e) {
			System.out.println(e.getMessage());
			RequestDispatcher rd = request.getRequestDispatcher("error.jsp");
			rd.forward(request, response);
		}
		
	
		
	}

}
